package com.atguigu.flink.chapter5.transform;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink05_Transform_KeyBy_5 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);
        env
          .fromElements(0, 1, 0, 20)
          .keyBy(x -> x)  // 默认按照key的hash值
          .sum(0)
          .print();

        env.execute();
    }
}
/*
这些function 都有一个Rich


new KeyGroupStreamPartitioner<>(keySelector, StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM))
DEFAULT_LOWER_BOUND_MAX_PARALLELISM = 128  maxParallelism

return KeyGroupRangeAssignment.assignKeyToParallelOperator(key, maxParallelism, numberOfChannels);
    key  0 1
    maxParallelism = 128
    numberOfChannels = 2


return computeOperatorIndexForKeyGroup(maxParallelism, parallelism, assignToKeyGroup(key, maxParallelism));
        assignToKeyGroup(key, maxParallelism) = MathUtils.murmurHash(keyHash) % maxParallelism  [0,128)

        [0,127] * 2 / 128
        keyGroupId * parallelism / maxParallelism;
 */
